﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using BLL;
using Common;

namespace Web
{
    public partial class AdminManagerAdd_UI : Form
    {
        public AdminManagerAdd_UI()
        {
            InitializeComponent();
        }
        public AdminManager_UI manager = null;
        private void button1_Click(object sender, EventArgs e)
        {
            int rows = this.manager.dataGridView1.RowCount;
            label5.Text = "";
            for (int i = 0; i < rows; i++)
            {
                string Columns1 = this.manager.dataGridView1.Rows[i].Cells[0].Value.ToString();
                if (Columns1 == textBox1.Text.Trim())
                {
                    label5.Text = "管理员编号已存在！";
                    return;
                }
            }
            Admin admin = new Admin();
            Admin_BLL admin_BLL = new Admin_BLL();
            Com com = new Com();
            admin.LoginId = textBox1.Text.Trim();
            admin.LoginPwd = textBox2.Text.Trim();
            admin.LoginRemark = textBox3.Text.Trim();
            admin.LoginType = comboBox1.SelectedItem.ToString();
            if (admin_BLL.AddAdmin(admin) > 0)
            {
                MessageBox.Show("添加信息成功！");
                //图书类型信息的绑定
                manager.dataGridView1.DataSource = manager.Admin_BLL.selectAdmin().Tables[0];

                //自动找到刚刚添加成功的新行，并选中
                com.AutoFindRow(textBox1.Text.Trim(), this.manager.dataGridView1);
                this.Close();
            }
            else
            {
                MessageBox.Show("添加信息失败！");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
